package com.tuanzi.loan.web.bean.receipt.statistics;

import com.tuanzi.loan.business.entity.extend.ExtendInfo;
import com.tuanzi.loan.business.entity.receipt.product.ReceiptProductInfo;
import com.tuanzi.loan.business.service.receipt.product.ReceiptProductInfoService;
import com.tuanzi.loan.business.service.receipt.statistics.ReceiptExtendStatisticsService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.receipt.statistics.ReceiptExtendStatisticsSearchRequest;
import com.tuanzi.loan.vo.response.receipt.statistics.ReceiptExtendStatisticsSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.receipt.statistics.ReceiptExtendStatisticsLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;


@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class ReceiptExtendStatisticsBean extends JSFListingBean<ReceiptExtendStatisticsSearchRequest,ReceiptExtendStatisticsSearchResponse> {


    @Autowired
    private ReceiptProductInfoService receiptProductInfoService;

    @Autowired
    private ReceiptExtendStatisticsService receiptExtendStatisticsService;

    private List<ReceiptProductInfo> receiptProductInfos;
    private List<ExtendInfo> extendInfos;
    
    @PostConstruct
    private void init() {
        initLazyDataModel();
    }

    public void search() {
        System.out.println("ReceiptExtendStatisticsBean.search");
    }

    public void onReset() {
        initLazyDataModel();
    }

    private void initLazyDataModel() {
        $ = new ReceiptExtendStatisticsSearchRequest();
        lazyDataModel = new ReceiptExtendStatisticsLazyDataModel($);
        receiptProductInfos = receiptProductInfoService.findAllProductIdAndName();
        extendInfos=receiptExtendStatisticsService.findAllExtendInfos();
    }

}
